package com.onehouse.infrastructure.repository.checkIn;

import com.onehouse.domain.checkIn.adapter.repository.ICheckInSubOrderRepository;
import com.onehouse.domain.checkIn.model.entity.CheckInRoom;
import com.onehouse.infrastructure.dao.CheckInRoomDao;
import com.onehouse.infrastructure.dao.po.CheckInRoomPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

@Repository
public class CheckInSubOrderRepository implements ICheckInSubOrderRepository {
    @Resource
    private CheckInRoomDao checkInRoomDao;

    @Override
    public void doSaveOrder(CheckInRoom checkInRoom, String checkInRoomsId) {
        checkInRoomDao.insert(this.convertToPO(checkInRoom, checkInRoomsId));
    }

    @Override
    public void updateOrder(CheckInRoom checkInRoom, String checkInRoomsId) {
        checkInRoomDao.update(this.convertToPO(checkInRoom, checkInRoomsId));
    }

    private CheckInRoomPO convertToPO(CheckInRoom checkInRoom, String checkInRoomsId) {
        CheckInRoomPO po = new CheckInRoomPO();
        po.setCheckInRoomId(checkInRoom.getCheckInRoomId());
        po.setCheckInRoomsId(checkInRoomsId);
        po.setCheckInDate(checkInRoom.getCheckInDate());
        po.setCheckOutDate(checkInRoom.getCheckOutDate());
        po.setRoomNumber(checkInRoom.getRoom().getRoomNumber());
        po.setBillStatus(checkInRoom.getCheckInBill().getBillStatus().toString());
        return po;
    }
}
